package com.woniu.component;

import com.woniu.entity.Order;
import com.woniu.mapper.OrderMapper;
import com.woniu.util.OrderContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@LiteflowComponent("notifyReject")
public class NotifyRejectNode extends NodeComponent {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void process() throws Exception {
        OrderContext context = this.getContextBean(OrderContext.class);
        String orderId = context.getOrderId();
        String errorMsg = context.getErrorMsg();

        // 更新订单状态为“已拒绝”（-1）
        Order order = new Order();
        order.setOrderId(orderId);
        order.setStatus(-1);

        orderMapper.update(order);
        context.setStatus(-1);
        context.setApprovalSuccess(false);

        System.out.println("❌ 订单 " + orderId + " 审批失败：" + (errorMsg != null ? errorMsg : "未知原因"));
    }
}